package com.youhome.clients.controller;

import com.youhome.common.exception.CustomException;
import com.youhome.common.response.Result;
import com.youhome.common.response.ResultCode;
import com.youhome.common.response.ResultPage;
import com.youhome.service.service.HouseThemeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by chen365 on 2018/03/09.
 */
@RestController
@RequestMapping(value = "/house/theme")
@Api(tags = "房源主题")
public class HouseThemeController {
    @Autowired
    private HouseThemeService houseThemeService;

    @ApiOperation(value = "房源主题列表", notes = "房源主题列表", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int", name = "pageNumber", value = "页码", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "int", name = "pageSize", value = "每页条数", required = true, paramType = "path")
    })
    @GetMapping(value = "/list/{pageNumber}/{pageSize}")
    public Object list(@PathVariable Integer pageNumber, @PathVariable Integer pageSize) throws CustomException {
        return new ResultPage<>(ResultCode.SUCCESS, houseThemeService.selectByBean(pageNumber, pageSize));
    }

    @ApiOperation(value = "房源主题详情", notes = "房源主题详情", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "Long", name = "themeId", value = "主题ID", required = true, paramType = "path")
    })
    @GetMapping(value = "/detail/{themeId}")
    public Object detail(@PathVariable("themeId") Long themeId) {
        return new Result(ResultCode.SUCCESS, houseThemeService.selectByPrimaryKey(themeId));
    }
}
